<template>
  <div class="payment-success">
    <div class="content">
      <h1 class="title">Processing payment...</h1>
      <p v-if="loading" class="message loading">Payment Successful!</p>
      <p v-else-if="error" class="message error">{{ error }}</p>
      <p v-else-if="success" class="message success">Payment processed. You can now close this page.</p>
    </div>
  </div>
</template>

<script>
import axios from 'axios';

export default {
  name: 'PaymentSuccess',
  data() {
    return {
      loading: true,
      error: null,
      success: false
    };
  },
  mounted() {
    this.handlePaymentCompletion();
  },
  methods: {
    handlePaymentCompletion() {
      this.$get(api.booking.close_page)
          .then(response => {
            if (response.data.close) {
              this.success = true;
            } else {
              this.error = 'Payment verification failed.';
            }
          })
          .catch(error => {
            this.error = 'Error during payment completion handling: ' + error.message;
          })
          .finally(() => {
            this.loading = false;
          });
    }
  }
};
</script>

<style scoped>
.payment-success {
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: Arial, sans-serif;
}

.content {
  margin-bottom: 2%;
  margin-top: 1%;
  text-align: center;
  padding: 40px;
  background: white;
  border-radius: 10px;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.25);
  color: #588baa;
  width: 80%;
}

.icon-container {
  margin-bottom: 20px;
}

.icon {
  font-size: 50px;
}

.success-icon {
  color: #81c784;
}

.error-icon {
  color: #e57373;
}

.title {
  font-family: math;
  font-size: 30px;
  margin-bottom: 20px;
  color: #588baa;
}

.message {
  font-size: 18px;
  margin: 10px 0;
}

.loading {
  color: #99b8cb;
}

.error {
  color: #e57373;
}

.success {
  color: #81c784;
}
::v-deep h1
{
  background: none;
  line-height: 1.1;
  padding: 20px 0 20px;
  margin: 0 0 25px 0;
  position: relative;
  border-bottom: 4px solid #cddce6;
}

</style>
